package com.thenmorethings.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.thenmorethings.entity.Essay;
import com.thenmorethings.service.EssayService;

public class EssayAction extends ActionSupport{

	@Resource
	private EssayService essayService;
	
	private Essay essay;
	private List<Essay> EssayList;
	
	public Essay getEssay() {
		return essay;
	}
	public void setEssay(Essay essay) {
		this.essay = essay;
	}
	public String EssayAllUI()
	{
		return "AllList";
	}
	public String EssayAdd()
	{
		if(essay!=null)
		{
			essayService.EssayAdd(essay);
			HttpServletResponse response = ServletActionContext.getResponse();
			String result = "success";
			try {
				PrintWriter pw = response.getWriter();
				pw.write(result);
				pw.flush();
				pw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		return null;
	}
	public String EssayDelete()
	{
		essayService.EssayDelete(essay.getId());
		return "deleteSuccess";
	}
	public String EssayAddUI()
	{
		return "success";
	}
	public String Essayfind()
	{
		if(essay!=null)
		{
			essay = essayService.EssayFind(essay.getId());
		}
		return "essayfind";  //跳转到编辑界面
	}
	public String EssayUpdate()
	{
		if(essay!=null)
		{
			essayService.EssayUpdate(essay);
			return "editor";
		}
		return "error";
	}
	


	public List<Essay> getEssayList() {
		return EssayList;
	}
	public void setEssayList(List<Essay> essayList) {
		EssayList = essayList;
	}
	
	
	
	
}
